package com.itany.corejava.code07_面向对象.继承;

/**
 * @author MissChen
 * @version 1.0
 * @date 2023 年11月03日 10:44
 */
public class Pet {
    private String name;
    private int age;
    // public Pet(){
    //     System.out.println("我是父类的无参的构造方法");
    // }
    public Pet(String name){
        this.name=name;
    }
    public Pet(int age){
        this.age=age;
    }
    public Pet(String name,int age){
        this.name=name;
        this.age=age;
    }
    public void setName(String name){
        this.name=name;
    }
    public String getName(){
        return name;
    }
    public void setAge(int age){
        this.age=age;
    }
    public int getAge(){
        return age;
    }
}
class Dog extends Pet{
    private String gender;
    // public Dog(){//如果子类有无参的构造方法，父类有多个构造方法，但是父类没有无参，此时会报错
    //     System.out.println("我是子类的无参构造方法");
    // }
    public Dog(String name,String gender){
        super(name);//调用父类构造方法时,只能调用一次,且super关键字必须处于第一行
        this.gender=gender;
    }
    public Dog(int age,String gender){
        super(age);//必须位于第一行,只能调用一次
        this.gender=gender;

    }
    public Dog(String name,int age,String gender){
        super(name,age);
        this.gender=gender;
    }
    public void setGender(String gender){
        this.gender=gender;
    }
    public String getGender(){
        return gender;
    }
}
class TestDog{
    public static void main(String[] args) {
        Dog dog=new Dog("大黄","公");
        System.out.println(dog.getName()+dog.getGender());
        Dog dog2=new Dog(3,"公");
        System.out.println(dog2.getAge()+dog2.getGender());
        Dog dog3=new Dog("阿黑",2,"公");
        System.out.println(dog3.getName()+dog3.getAge()+dog3.getGender());
    }
}